package com.wlyuan.open.remote.facade;

import com.alibaba.fastjson.JSON;
import com.wlyuan.basic.api.ICustomerService;
import com.wlyuan.basic.dto.customer.CustomerDetailDTO;
import com.wlyuan.basic.dto.customer.OfflineCustomerCreationDTO;
import com.wlyuan.open.domain.source.dispatcher.customer.CreateCustomer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author lijing
 * @description
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class CustomerFacade {
    @Resource
    private ICustomerService customerService;

    public CustomerDetailDTO createCustomer(CreateCustomer createCustomer) {
        var creation = new OfflineCustomerCreationDTO();
        if (StringUtils.isBlank(createCustomer.getContactMobile())) {
            createCustomer.setContactMobile("-");
        }
        if (StringUtils.isBlank(createCustomer.getContactName())) {
            createCustomer.setContactName("-");
        }
        BeanUtils.copyProperties(createCustomer, creation);
        logger.info("创建发货方：{},{}", JSON.toJSON(createCustomer), JSON.toJSON(creation));
        return customerService.createShould(creation);

    }
}
